<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>设备分类管理</title>
    <link rel="stylesheet" type="text/css" href="${s.base}/lib/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/index.css"/>
    <link rel="stylesheet" type="text/css" href="${s.base}/css/base/theme/theme.css"/>
</head>
<body>
<div class="wrap-container clearfix">
    <div class="column-content-detail">
        <form class="layui-form">
            <div class="search-cont clearfix" id="tool">
                <div class="operation-btn-cont">
                    <div class="operright cyt-retract-close hideMenu">收起筛选<i class="iconfont">&#xe658;</i></div>
                    <div class="operright cyt-retract-open showMenu" style="display: none;">展开筛选<i class="iconfont">&#xe936;</i></div>
                    <@shiro.hasPermission name="sys:menu:add">
                    <button class="layui-btn layui-btn-normal layui-option-sm" type="button" id="devicesTypeAddOrEdit"><i class="iconfont marr5">&#xe65e;</i>添加</button>
                </@shiro.hasPermission>
            <button class="layui-btn layui-btn-normal layui-option-sm up-all" type="button"><i class="iconfont marr5">&#xe66f;</i>收起</button>
            <button class="layui-btn layui-btn-normal layui-option-sm down-all" type="button"><i class="iconfont marr5">&#xe6a6;</i>展开</button>
            <div class="triangle-bottom"></div>
            <div class="triangle-top"></div>
    </div>
    <div class="search-details">
        <div class="layui-form-item marb5">
            <div class="layui-inline">
                <label class="layui-form-label">设备分类名称：</label>
                <div class="layui-input-inline">
                    <input type="text" name="name" id="name" placeholder="请输入设备分类名称" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-inline marl8">
                <button class="layui-btn layui-btn-normal" type="button" lay-submit="" id="seacherBtn">搜索</button>
                <button class="layui-btn layui-btn-normal" type="reset">重置</button>
            </div>
        </div>
    </div>
</div>
</form>
<div class="layui-form" id="table-list">
    <table lay-filter="devicesTypeList" class="layui-table layui-formcy-list-table" id="test-tree-table"></table>
</div>
</div>
</div>
<script src="${s.base}/lib/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script src="${s.base}/js/common.js" type="text/javascript" charset="utf-8"></script>
<script>
    var applyId='${applyId}';
    layui.use(['jquery', 'page', 'baseutil', 'treetable'], function () {
        var $ = layui.jquery,
            page = layui.page,
            baseutil = layui.baseutil,
            treetable = layui.treetable;
        page.initDict("apply_menu_type",function (dictData) {
            var renderTable = function () {
                var name = $('#name').val();
                baseutil.post("/wb/wbdevicestype/findList", {"applyId": applyId, name: name}, function (result) {
                    var data = [];
                    if (0 === result.code) {
                        for (var i = 0; i < result.data.length; i++) {
                            var obj = result.data[i];
                            var d = {};
                            d.id = obj.id;
                            d.name = obj.name;
                            if (isBlank(obj.parentId) || isNotBlank(name)) {
                                d.pid = 0;
                            } else {
                                d.pid = obj.parentId;
                            }
                            d.sort = obj.sort;
                            d.remarks=obj.remarks;
                            data.push(d);
                        }
                        treetable.render({
                            elem: '#test-tree-table',
                            data: data,
                            field: 'name',
                            is_checkbox: true,
                            cols: [
                                {
                                    field: 'name',
                                    title: '设备分类名',
                                    width: '30%'
                                }, {
                                    field: 'remarks',
                                    title: '备注',
                                    width: '25%'
                                }, {
                                    field: 'sort',
                                    title: '排序',
                                    width: '20%'
                                },  {
                                    title: '操作',
                                    align: 'center',
                                    width: '25%',
                                    template: function () {
                                        var tem = [];
                                        tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-purple"  lay-filter="add">添加</a>');
                                        tem.push('<a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-green"  lay-filter="edit">编辑</a>');
                                        tem.push('<button class="layui-btn layui-btn-radius layui-btn-primary layui-btn-sm layui-smbtn-red" lay-filter="delete">删除</button>');
                                        return tem.join(' <font> </font> ')
                                    }
                                }
                            ]
                        });
                    } else {
                        top.layer.msg(result.msg);
                    }
                });

                treetable.on('treetable(edit)', function (data) {
                    page.editPopup("/work/wb/wbdevicestype/getEdit?id=" + data.item.id+"&applyId="+applyId, "设备分类编辑", "700px","500px");
                });

                treetable.on('treetable(add)', function (data) {
                    page.editPopup("/work/wb/wbdevicestype/getEdit?parentId="+data.item.id+"&applyId="+applyId, "设备分类新增", "700px","500px");
                });

                treetable.on('treetable(delete)', function (data) {
                    page.delete("/work/wb/wbdevicestype/remove", {"id": data.item.id, "_method": "DELETE"}, "确定删除该分类吗？", function (data) {
                        top.layer.msg(data);
                        window.location.reload();
                    });
                });
            };

            renderTable();
            $('#seacherBtn').click(function () {
                renderTable();
            });

            $('.up-all').click(function () {
                treetable.all('up');
            });

            $('.down-all').click(function () {
                treetable.all('down');
            });
        });

        $("#devicesTypeAddOrEdit").bind("click",function () {
            page.editPopup("/work/wb/wbdevicestype/getEdit?applyId="+applyId, "设备分类添加","700px","500px");
        });


    });

</script>
</body>
</html>